package cn.dancepeak.artcle.service.impl;

import cn.dancepeak.artcle.mapper.ParamManagerMapper;
import cn.dancepeak.artcle.service.IParamManagerServiceImpl;
import cn.dancepeak.article.domain.ParamManager;
import cn.dancepeak.article.query.ParamManagerQuery;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class ParamManagerServiceImplImpl implements IParamManagerServiceImpl {
    @Autowired
    private ParamManagerMapper paramManagerMapper;
    @Override
    @Transactional
    public void add(ParamManager paramManager) {
        //保存员工返回自增id
        paramManagerMapper.insert(paramManager);
    }

    @Override
    @Transactional
    public void update(ParamManager paramManager) {
        //用户名不能修改   禁用  在前端写
        paramManagerMapper.updateById(paramManager);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        paramManagerMapper.deleteById(id);
    }

    @Override
    @Transactional
    public void deleteByList(List<Long> ids) {
        paramManagerMapper.deleteByList(ids);
    }

    @Override
    public ParamManager getById(Long id) {
        return paramManagerMapper.selectById(id);
    }

    @Override
    public PageInfo<ParamManager> page(ParamManagerQuery paramManagerQuery) {
        // 1.下面这句代码表示开启分页，会将紧挨着这句代码的下一次数据库执行进行分页，切记一定要放在要分页的SQL语句前面执行
        // 2.执行SQL语句带条件查询，SQL语句不需要进行分页
        PageHelper.startPage(paramManagerQuery.getCurrentPage(), paramManagerQuery.getPageSize());
        List<ParamManager> paramManager = paramManagerMapper.list(paramManagerQuery);
        // 3.将查询结果转换为PageInfo对象，PageInfo对象中有前端分页所需要的各种参数
        PageInfo<ParamManager> pageInfo = new PageInfo<>(paramManager);
        // 4.响应总条数和分页信息
        return pageInfo;
    }

    @Override
    @Transactional
    public void updateState(ParamManager paramManager) {
        paramManagerMapper.updateState(paramManager);
    }
}
